import { defineStore } from 'pinia'
import { ref } from 'vue'

interface TreeNode {
  id: number
  label: string
  children?: TreeNode[]
}

export const useSidebarTreeStore = defineStore('sidebarTree', () => {
  const treeData = ref<TreeNode[]>([
    {
      id: 1,
      label: '基础资料',
      children: [
        {
          id: 2,
          label: '货品信息',
          children: [
            { id: 3, label: '大类资料' },
            { id: 3, label: '小类资料' },
            { id: 3, label: '计量单位' },
            { id: 3, label: '品牌资料' },
            { id: 3, label: '供应商资料' },
            { id: 3, label: '仓库资料' },
            { id: 3, label: '仓库资料' },
            { id: 3, label: '仓库资料' },
          ],
        },
        { id: 3, label: '大类资料' },
        { id: 3, label: '小类资料' },
      ],
    },
    {
      id: 4,
      label: '一级节点2',
      children: [
        { id: 5, label: '二级节点3' },
        { id: 6, label: '二级节点4' },
      ],
    },
    {
      id: 4,
      label: '一级节点2',
      children: [
        { id: 5, label: '二级节点3' },
        { id: 6, label: '二级节点4' },
      ],
    },
    {
      id: 4,
      label: '一级节点2',
      children: [
        { id: 5, label: '二级节点3' },
        { id: 6, label: '二级节点4' },
      ],
    },
  ])
  const selectedNodeLabel = ref('')

  const handleNodeClick = (data: TreeNode) => {
    selectedNodeLabel.value = data.label
  }

  return { treeData, selectedNodeLabel, handleNodeClick }
})
